﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="材料到货记录录入.aspx.cs" Inherits="syc.Store.材料到货记录录入" %>
<html>
<head>
<title></title>
<style>
div.AutoComplete_Container{position:absolute; z-index:2;border:solid 1px #dd3333;background-color:#ffffff;padding:1px;font-size:14px;color:#ff0000;}
#AutoComplete_CurrentLine{ background-color:#0000cc;}
tr.AutoComplete_Row{font-size:14px;color:#6f320a;height:18px;cursor:pointer;}
tr.AutoComplete_HotRow{font-size:14px;color:#6f320a; background-color:#ffee88;height:18px;cursor:pointer;}
tr{height:34px;}
</style>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="select @单据ID=t1.单据ID,@材料ID=t1.材料ID,@单位ID=t1.单位ID,@日期=t1.日期,@单价=cast(t1.单价 as float)
,@数量0=cast(t1.数量0 as float),@数量=cast(t1.数量 as float),@备注=t1.备注,@品名=t2.品名,@规格=t2.规格,@单位=t2.单位 from 材料到发货 t1
left outer join 物料品种 t2 on t2.id=t1.材料ID where t1.ID=@ID;"
InsertCommand="insert into 材料到发货(材料ID,单位ID,日期,单价,数量0,数量,金额,保管员,备注)
values(@材料ID,@单位ID,@日期,@单价,@数量0,@数量,ROUND(@数量*@单价,2),@保管员,@备注);set @ID=@@IDENTITY;"
UpdateCommand="update 材料到发货 set 材料ID=@材料ID,单位ID=@单位ID,日期=@日期
,单价=@单价,数量0=@数量0,数量=@数量,金额=ROUND(@数量*@单价,2),备注=@备注 where ID=@ID and 单据ID=0;"
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
oninserted="SqlDataSource1_Inserted" onselected="SqlDataSource1_Selected" >
<SelectParameters>
<asp:Parameter Name="ID" DbType="Int32" Size="4" />
<asp:Parameter Name="材料ID" DbType="Int32" Size="4" Direction="Output" />
<asp:Parameter Name="单位ID" DbType="Int32" Size="4" Direction="Output" />
<asp:Parameter Name="数量0" DbType="Double" Size="9" Direction="Output" />
<asp:Parameter Name="数量" DbType="Double" Size="9" Direction="Output" />
<asp:Parameter Name="日期" DbType="Date" Size="3" Direction="Output" />
<asp:Parameter Name="单价" DbType="Double" Size="13" Direction="Output" />
<asp:Parameter Name="备注" DbType="String"  Size="100" Direction="Output" />
<asp:Parameter Name="单据ID" DbType="Int32" Size="4" Direction="Output" />
<asp:Parameter Name="品名" DbType="String"  Size="40" Direction="Output" />
<asp:Parameter Name="规格" DbType="AnsiString" Size="40" Direction="Output" />
<asp:Parameter Name="单位" DbType="AnsiString"  Size="10" Direction="Output" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="ID" DbType="Int32" Size="4" Direction="Output" />
<asp:ControlParameter Name="材料ID" DbType="Int32" Size="4" ControlID="BianMa"/>
<asp:ControlParameter Name="单位ID" DbType="Int32" Size="4" ControlID="GongHuo"/>
<asp:ControlParameter Name="数量0" DbType="Decimal" Size="9" ControlID="ShuLiang0"/>
<asp:ControlParameter Name="数量" DbType="Decimal" Size="9" ControlID="ShuLiang"/>
<asp:ControlParameter Name="日期" DbType="Date" Size="3" ControlID="Date1"/>
<asp:ControlParameter Name="单价" DbType="Decimal" Size="13" ControlID="DanJia"/>
<asp:ControlParameter Name="备注" DbType="String"  Size="100" ControlID="BeiZhu"/>
<asp:Parameter Name="保管员" DbType="String" Size="20" />
</InsertParameters>
<UpdateParameters>
<asp:ControlParameter Name="ID" DbType="Int32" Size="4" ControlID="Label_ID"/>
<asp:ControlParameter Name="材料ID" DbType="Int32" Size="4" ControlID="BianMa"/>
<asp:ControlParameter Name="单位ID" DbType="Int32" Size="4" ControlID="GongHuo"/>
<asp:ControlParameter Name="数量0" DbType="Decimal" Size="9" ControlID="ShuLiang0"/>
<asp:ControlParameter Name="数量" DbType="Decimal" Size="9" ControlID="ShuLiang"/>
<asp:ControlParameter Name="日期" DbType="Date" Size="3" ControlID="Date1"/>
<asp:ControlParameter Name="单价" DbType="Decimal" Size="13" ControlID="DanJia"/>
<asp:ControlParameter Name="备注" DbType="String"  Size="100" ControlID="BeiZhu"/>
</UpdateParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
SelectCommand="select 0 as ID,'' as 名称 union all select ID, 名称 FROM 材料供货单位"></asp:SqlDataSource>

<asp:Label ID="Label_ID" runat="server" Text="0" Visible="false"></asp:Label>

<div id="wintop" class="wintop" style="display:none;">材料到货记录录入</div>

<asp:Panel ID="Panel1" runat="server" CssClass="panel">
<asp:Button ID="Button_Save" runat="server" Text="保 存" UseSubmitBehavior="false"
        CssClass="button" onclick="Button_Save_Click"  />

<asp:Button ID="Button_ReNew" runat="server" Text="录入新记录" UseSubmitBehavior="false" Visible="false"
        CssClass="button2" onclick="Button_ReNew_Click" />
        
<asp:Button ID="Button_Close" runat="server" Text="关 闭" UseSubmitBehavior="false"  Visible="true"
        CssClass="button" OnClientClick="parent.swin2_close();return false;" />

</asp:Panel>

<asp:Panel ID="Panel2" runat="server" CssClass="panel" HorizontalAlign="Center">

<table border=1 style="border-collapse:separate;font-size:14px;margin-top:7px;margin-bottom:28px;">
<tr>
<td height=50 colspan=4 align=center style="font-weight:bold; letter-spacing:20px;font-size:20px;border:none;">到货信息</td>
</tr>

<tr>
<td height=40 align=right>品名：</td>
<td>
<asp:TextBox ID="PinMing" runat="server" CssClass="textbox" Width="120px"></asp:TextBox>
</td>
<td align=right>规格：</td>
<td>
    <asp:Label ID="GuiGe" runat="server" Text="..."></asp:Label></td>
</tr>

<tr>
<td height=40 align=right>物料编码：</td>
<td>
<asp:TextBox ID="BianMa" runat="server" CssClass="textbox" Width="120px"></asp:TextBox>
</td>
<td align=right>供货单位：</td>
<td><asp:DropDownList 
        ID="GongHuo" runat="server" DataSourceID="SqlDataSource2" Width="140px"
        DataTextField="名称" DataValueField="ID"></asp:DropDownList></td>
</tr>

<tr>
<td height=40 width=100 align=right>应该到货：</td>
<td width=180><asp:TextBox ID="ShuLiang0" runat="server" CssClass="textbox" Width="120px"></asp:TextBox><asp:Label ID="DanWei1" runat="server" Text=""></asp:Label></td>
<td width=100 align=right>实际到货：</td>
<td width=180><asp:TextBox ID="ShuLiang" runat="server" CssClass="textbox" Width="120px"></asp:TextBox><asp:Label ID="DanWei2" runat="server" Text=""></asp:Label></td>
</tr>

<tr>
<td height=40 align=right>到货日期：</td>
<td><asp:TextBox ID="Date1" runat="server" CssClass="textbox" Width="120px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" /></td>
<td align=right>单价(元)：</td>
<td><asp:TextBox ID="DanJia" runat="server" CssClass="textbox" Width="120"></asp:TextBox></td>
</tr>
<tr>
<td height=40 align=right>备注：</td>
<td colspan="3"><asp:TextBox ID="BeiZhu" runat="server" CssClass="textbox" Width="407px"></asp:TextBox></td>
</tr>
</table>

</asp:Panel>

</form>

<script >
    var notice = "<%=this.Notice %>";
    if (notice != "") {
        parent.showmsgbox(notice);
    }

    var textboxs = document.getElementsByTagName("input");
    var i;
    for (i = 0; i < textboxs.length; i++) {
        if (textboxs[i].className == "textbox") {
            textboxs[i].onchange = function(e) { this.className = "textbox-changed"; if (this.id == "ShuLiang0") document.getElementById("ShuLiang").value = this.value; };
            textboxs[i].onfocus = function(e) { this.select(); };
        }
        else if (textboxs[i].className == "pageturn" || textboxs[i].className == "intxt1" || textboxs[i].className == "textbox") {
            textboxs[i].onfocus = function(e) { this.select(); };
        }
    }

    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.id == "BeiZhu") return;
        if (tag.tagName == "INPUT" && tag.className == "textbox" || tag.tagName == "SELECT" || tag.tagName == "DIV") {
            if (e.keyCode == 13) {
                e.keyCode = 9;
            }
        }
        else if (e.keyCode == 8) {
            return false;
        }
    }
    function makecalendar(d, o) {
        obj = o;
        idate = makedate(d);
        cdate = new Date(idate.getFullYear(), idate.getMonth(), 1);
        ds.style.left = (getObjectLeft(o) + 2 ) + "px";
        ds.style.top = (getObjectTop(o) - 105) + "px";
        ds.style.display = 'block';
        showcalendar();
    }

    var BianMa = document.getElementById("BianMa");
    var GuiGe = document.getElementById("GuiGe");
    var DanWei1 = document.getElementById("DanWei1");
    var DanWei2 = document.getElementById("DanWei2");
    var DanJia = document.getElementById("DanJia");

    //自动完成
    var AutoComplete_Container = document.getElementById("AutoComplete_Container");
    if (!AutoComplete_Container) {//创建容器
        AutoComplete_Container = document.createElement("DIV");
        AutoComplete_Container.id = "AutoComplete_Container";
        AutoComplete_Container.className = "AutoComplete_Container";
        AutoComplete_Container.style.display = "none";
        document.body.appendChild(AutoComplete_Container);
    }
    var AutoComplete_Lists = new Array();
    var AutoComplete_Target = null;
    var AutoComplete_LastValue = "";
    function AutoComplete_SetHotRow(o) {
        var hotrow = document.getElementById("AutoComplete_HotRow");
        hotrow.id = "";
        hotrow.className = "AutoComplete_Row";
        o.id = "AutoComplete_HotRow";
        o.className = "AutoComplete_HotRow";
    }
    function AutoComplete_Select() {
        var hotrow = document.getElementById("AutoComplete_HotRow");
        if (hotrow) {
            var li = AutoComplete_Lists[hotrow.rowIndex].split("\t");
            BianMa.value = li[0];
            AutoComplete_Target.value = li[1];
            GuiGe.innerHTML = li[2];
            DanWei1.innerHTML = li[3];
            DanWei2.innerHTML = li[3];
            DanJia.value = li[4];
        }
    }
    function AutoComplete_Response(http) {
        if (http.status != 200) {
            alert("服务器错误: " + http.status + " " + http.statusText);
            return;
        }
        if (http.responseText == "") {
            AutoComplete_Container.innerHTML = "<div style=padding:3px;font-size:14px;>没有查询到您录入的品种</div>";
        }
        else {
            var className = "AutoComplete_HotRow";
            var rs = http.responseText.split("\n");
            var tmp = "<table>";
            var cs;
            var id = " id=AutoComplete_HotRow";
            for (var i = 0; i < rs.length - 1; i++) {
                AutoComplete_Lists[i] = rs[i];
                cs = rs[i].split("\t");
                tmp += "<tr" + id + " class=" + className + " onmousemove=AutoComplete_SetHotRow(this); onmousedown=AutoComplete_Select();><td style='width:90px;padding:1px 2px 0px 2px;'>"
                    + cs[0] + "</td><td align=center style=width:120px>"
                    + cs[1] + "</td><td align=center style=width:120px>"
                    + cs[2] + "</td><td align=center style=width:80px>"
                    + cs[4] + "/" + cs[3] + "</td></tr>";
                className = "AutoComplete_Row";
                id = "";
            }
            tmp += "</table>";
            AutoComplete_Container.innerHTML = tmp;
        }

        AutoComplete_Container.style.display = "";
        AutoComplete_Container.style.top = (getObjectTop(AutoComplete_Target) + AutoComplete_Target.clientHeight + 2) + "px";
        AutoComplete_Container.style.left = (getObjectLeft(AutoComplete_Target)) + "px";
    };
    function AutoComplete_HideContainer() {
        if (AutoComplete_Target == null) {
            AutoComplete_Container.style.display = "none";
        }
    }
    function AutoComplete_SetValue(value) {
        if (typeof (AutoComplete_Target.value) != "undefined") AutoComplete_Target.value = value;
        else if (typeof (AutoComplete_Target.innerText) != "undefined") AutoComplete_Target.innerText = value;
        else if (typeof (AutoComplete_Target.textContent) != "undefined") AutoComplete_Target.textContent = value;
    }
    function AutoComplete() {
        if (AutoComplete_Target == null) {
            AutoComplete_Container.style.display = "none";
        }
        else if (AutoComplete_Target != document.activeElement) {
            AutoComplete_Target = null;
            setTimeout("AutoComplete_HideContainer()", 100);
        }
        else {
            var txt;
            if (typeof (AutoComplete_Target.value) != "undefined") txt = AutoComplete_Target.value;
            else if (typeof (AutoComplete_Target.innerText) != "undefined") txt = AutoComplete_Target.innerText;
            else if (typeof (AutoComplete_Target.textContent) != "undefined") txt = AutoComplete_Target.textContent;

            txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
            if (txt == "") {
                AutoComplete_Container.style.display = "none";
            }
            else if (txt != AutoComplete_LastValue) {
                AutoComplete_LastValue = txt;
                var request = createRequest(AutoComplete_Response);
                request.open("GET", encodeURI("/Store/物料品种查询.ashx?s=" + txt), true);
                request.send(null);
            }
        }
        setTimeout("AutoComplete()", 200);
    }

    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.tagName != "INPUT" || tag.className != "textbox") return;
        if (tag.id == "BeiZhu") return;
        
        if (tag == AutoComplete_Target && AutoComplete_Container.style.display != "none") {
            if (e.keyCode != 9) {
                BianMa.value = "";
                GuiGe.innerHTML = "...";
                DanWei1.innerHTML = "";
                DanWei2.innerHTML = "";
                DanJia.value = "";  
            }

            if (e.keyCode == 38) {
                var hotrow = document.getElementById("AutoComplete_HotRow");
                if (hotrow) {
                    var lt = hotrow.parentNode.parentNode;
                    hotrow.id = "";
                    hotrow.className = "AutoComplete_Row";
                    if (hotrow.rowIndex > 0) {
                        lt.rows[hotrow.rowIndex - 1].id = "AutoComplete_HotRow";
                        lt.rows[hotrow.rowIndex - 1].className = "AutoComplete_HotRow";
                    }
                    else {
                        lt.rows[lt.rows.length - 1].id = "AutoComplete_HotRow";
                        lt.rows[lt.rows.length - 1].className = "AutoComplete_HotRow";
                    }
                }
            }
            else if (e.keyCode == 40) {
                var hotrow = document.getElementById("AutoComplete_HotRow");
                if (hotrow) {
                    var lt = hotrow.parentNode.parentNode;
                    hotrow.id = "";
                    hotrow.className = "AutoComplete_Row";
                    if (hotrow.rowIndex < lt.rows.length - 1) {
                        lt.rows[hotrow.rowIndex + 1].id = "AutoComplete_HotRow";
                        lt.rows[hotrow.rowIndex + 1].className = "AutoComplete_HotRow";
                    }
                    else {
                        lt.rows[0].id = "AutoComplete_HotRow";
                        lt.rows[0].className = "AutoComplete_HotRow";
                    }
                }
            }
            else if (e.keyCode == 13) {
                AutoComplete_Select();
                e.keyCode = 9;
            }
            else if (e.keyCode == 27) {
                AutoComplete_LastValue = "";
                tag.value = "";
            }
        }
        else if (e.keyCode == 13) {
            e.keyCode = 9;
        }

    }
    setTimeout("AutoComplete()", 200);
    //自动完成结束
    document.getElementById("PinMing").onfocus = function() {
        AutoComplete_LastValue = "";
        AutoComplete_Target = this;
        this.select();
    }
</script>
</body>
</html>
